package userInterface;
import dataProces.DatabaseOperations;
import dataProces.FileOperations;

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class AccountInformation extends JDialog implements ActionListener{
    JPanel[] jPanels=new JPanel[6];
    JButton[] jButtons=new JButton[2];
    JTextField[] jFields=new JTextField[10];
    String[] prompt={"账号","密码","姓名","电话","身份证","存款(元)","投资(金)","投资(银)","投资(铜)","投资(铁)","信息导出","返回"};
    String[] items={"account","password","name","phone","identity_card","money","gold","silver","copper","iron"};
    String[] userData=new String[10];
    DatabaseOperations dOperations=new DatabaseOperations();
    public AccountInformation(){
        Container container=this.getContentPane();
        container.setLayout(new GridLayout(6,1));
        for(int i=0;i<jPanels.length;i++){
            jPanels[i]=new JPanel();
            if(i<5)
                for(int j=0;j<2;j++){
                    jPanels[i].add(new JLabel(prompt[2*i+j]));
                    jFields[2*i+j]=new JTextField(15);
                    jFields[2*i+j].setEditable(false);
                    if(2*i+j<5)
                        userData[2*i+j]=dOperations.dataQueries("user",Login.user,items[2*i+j]);
                    else userData[2*i+j]=dOperations.dataQueries("investment",Login.user,items[2*i+j]);
                    jFields[2*i+j].setText(userData[2*i+j]);
                    jPanels[i].add(jFields[2*i+j]);
                }
            else for(int j=0;j<2;j++){
                jButtons[j]=new JButton(prompt[2*i+j]);
                jButtons[j].addActionListener(this);
                jPanels[i].add(jButtons[j]);
            }
            container.add(jPanels[i]);
        }
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(500, 300);
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screen.width - 500) / 2, (screen.height - 300) / 2);
        setTitle(prompt[3]);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==jButtons[0]){
            dispose();
            new FileOperations().exportTxt(prompt,userData);
            new AccountInformation();
        }else if(e.getSource()==jButtons[1]){
            dispose();
            new UserMenu();
        }
    }
    public static void main(String[] args) {
        new AccountInformation();
    }
}
